<?php require_once('Connections/MYCONN.php'); ?>
<?php


if(isset($_GET["Action"]) && $_GET["Action"] != "" && $_GET["Action"] == 99)
{
	if(isset($_GET["TblName"]) && $_GET["TblName"] != "")
	{
		$TblName = $_GET["TblName"];
	}
	
	if(isset($_GET["ID"]) && $_GET["ID"] != "")
	{
		$ID = base64_decode($_GET["ID"]);
	}
/* 	
	$deleteSQL ="DELETE FROM tb_cash WHERE ParentID = ".$ID;
	mysql_select_db($database_MYCONN, $MYCONN);
	$Result1 = mysql_query($deleteSQL, $MYCONN) or die(mysql_error());
	
	$deleteSQL ="DELETE FROM tb_checks WHERE ParentID = ".$ID;
	mysql_select_db($database_MYCONN, $MYCONN);
	$Result1 = mysql_query($deleteSQL, $MYCONN) or die(mysql_error());
	
	$deleteSQL ="DELETE FROM tb_creditcard WHERE ParentID = ".$ID;
	mysql_select_db($database_MYCONN, $MYCONN);
	$Result1 = mysql_query($deleteSQL, $MYCONN) or die(mysql_error());
	
	$deleteSQL ="DELETE FROM tb_deposits WHERE ParentID = ".$ID;
	mysql_select_db($database_MYCONN, $MYCONN);
	$Result1 = mysql_query($deleteSQL, $MYCONN) or die(mysql_error());
	
	$deleteSQL ="DELETE FROM tb_lunchamt WHERE ParentID = ".$ID;
	mysql_select_db($database_MYCONN, $MYCONN);
	$Result1 = mysql_query($deleteSQL, $MYCONN) or die(mysql_error());
	
	$deleteSQL ="DELETE FROM tb_metrocard WHERE ParentID = ".$ID;
	mysql_select_db($database_MYCONN, $MYCONN);
	$Result1 = mysql_query($deleteSQL, $MYCONN) or die(mysql_error());
	
	$deleteSQL ="DELETE FROM tb_overrings WHERE ParentID = ".$ID;
	mysql_select_db($database_MYCONN, $MYCONN);
	$Result1 = mysql_query($deleteSQL, $MYCONN) or die(mysql_error());
	
	$deleteSQL ="DELETE FROM tb_payouts WHERE ParentID = ".$ID;
	mysql_select_db($database_MYCONN, $MYCONN);
	$Result1 = mysql_query($deleteSQL, $MYCONN) or die(mysql_error());
 */	
	$deleteSQL ="DELETE FROM ".$TblName."  WHERE ID = ".$ID;
	mysql_select_db($database_MYCONN, $MYCONN);
	$Result1 = mysql_query($deleteSQL, $MYCONN) or die(mysql_error());

	echo $Result1;
}


if(isset($_GET["Action"]) && $_GET["Action"] != "" && $_GET["Action"] == -1)
{
	if(isset($_GET["TblName"]) && $_GET["TblName"] != "")
	{
		$TblName = $_GET["TblName"];
	}
	
	if(isset($_GET["ID"]) && $_GET["ID"] != "")
	{
		$ID = base64_decode($_GET["ID"]);
	}
	
	$deleteSQL ="DELETE FROM ".$TblName."  WHERE ID = ".$ID;
	
	mysql_select_db($database_MYCONN, $MYCONN);
	$Result1 = mysql_query($deleteSQL, $MYCONN) or die(mysql_error());
	
	echo $Result1;
}

if(isset($_GET["Action"]) && $_GET["Action"] != "" && $_GET["Action"] == "100")
{
	if(isset($_GET["TblName"]) && $_GET["TblName"] != "")
	{
		$TblName = $_GET["TblName"];
	}
	
	if(isset($_GET["CName"]) && $_GET["CName"] != "")
	{
		$CName = $_GET["CName"];
	}
	if(isset($_GET["ID"]) && $_GET["ID"] != "")
	{
		$ID = base64_decode($_GET["ID"]);
	}
	if(isset($_GET["Value"]) && $_GET["Value"] != "")
	{
		$Value = $_GET["Value"];
	}
	
	$updateSQL ="UPDATE ".$TblName." SET ".$CName."='".$Value."' WHERE ID = ".$ID;
	
	mysql_select_db($database_MYCONN, $MYCONN);
	$Result1 = mysql_query($updateSQL, $MYCONN) or die(mysql_error());
	
	echo $Result1;
}


if(isset($_GET["Action"]) && $_GET["Action"] != "" && $_GET["Action"] == 999)
{
	if(isset($_GET["TblName"]) && $_GET["TblName"] != "")
	{
		$TblName = $_GET["TblName"];
	}
	
	if(isset($_GET["ID"]) && $_GET["ID"] != "")
	{
		$ID = base64_decode($_GET["ID"]);
	}
	
	if(isset($_GET["Value"]) && $_GET["Value"] != "")
	{
		$Value = $_GET["Value"];
	}
	
	if(isset($_GET["CName"]) && $_GET["CName"] != "")
	{
		$CName = $_GET["CName"];
	}
	


	$sqlCount = "select ParentID from tb_master_register where ParentID='".$ID."' and CashType='".$CName."'";

	mysql_select_db($database_MYCONN, $MYCONN);
	//$Result1 = mysql_query($updateSQL, $MYCONN) or die(mysql_error());
	
	$Result1 = mysql_query($sqlCount, $MYCONN) or die(mysql_error());
	$totalRows1 = mysql_num_rows($Result1);
//echo $totalRows1;

 	if($totalRows1 >0){
		$updateSQL ="UPDATE ".$TblName." SET Amount ='".$Value."' WHERE CashType='".$CName."' AND ParentID = ".$ID;
	}
	else
	{
		$updateSQL ="INSERT INTO ".$TblName."(ParentID, Amount, CashType) VALUES ('".$ID."', '".$Value."', '".$CName."') ";
	}
	//echo $Result1;


	$Result2 = mysql_query($updateSQL, $MYCONN) or die(mysql_error());
	
	$totalRows2 = mysql_num_rows($Result1);

	echo $Result2; 
}
//echo $Result1;






?>